package com.book.iphone;

import com.book.book.domain.CommunicateDO;
import com.book.book.domain.UsersDO;
import com.book.book.service.CommunicateService;
import com.book.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.jws.WebParam;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 图书漂流控制器
 * Created by siyuan
 * on 2018/1/29.
 */

@RequestMapping("/iphone/social")
@Controller
public class socialController {

    @Autowired
    CommunicateService communicateService;


    /**
     * 获取这本书的详细评论
     * @param model
     * @param bookid
     * @return
     */
    @GetMapping("/book/{bookid}")
    String getCommunicate(Model model ,@PathVariable("bookid") String bookid ) {
        Map<String, Object> map = new HashMap();
        map.put("limit", 10);
        map.put("offset", 0);
        map.put("bookId", Integer.parseInt(bookid));
        Query query = new Query(map);
        List<CommunicateDO> bookCommunicate = communicateService.listWithName(map);
//        if (bookCommunicate.size() > 0) {
        model.addAttribute("bookCommunicate", bookCommunicate);
//    }
        return "book/phone/html/exchange";
  }


    @GetMapping("/ws")
    String catWsHtml(HttpServletRequest request, Model model) {
        UsersDO usersDO = (UsersDO) request.getSession().getAttribute("userinfo");
        model.addAttribute("usersDO",usersDO);
        return "book/phone/html/communciate";
    }

}
